package net.shopxx.service.impl;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;

import javax.annotation.Resource;
import javax.servlet.ServletContext;

import net.shopxx.bean.HtmlConfig;
import net.shopxx.bean.Pager;
import net.shopxx.bean.SystemConfig;
import net.shopxx.common.CommentUtil;
import net.shopxx.dao.ArticleDao;
import net.shopxx.dao.BrandDao;
import net.shopxx.dao.FlagshipStoreDao;
import net.shopxx.dao.ProductDao;
import net.shopxx.entity.Article;
import net.shopxx.entity.ArticleCategory;
import net.shopxx.entity.Brand;
import net.shopxx.entity.CategoryBean;
import net.shopxx.entity.FlagshipStore;
import net.shopxx.entity.Groupbuy;
import net.shopxx.entity.Indexfloor;
import net.shopxx.entity.Product;
import net.shopxx.entity.ProductCategory;
import net.shopxx.entity.ProductColor;
import net.shopxx.entity.ProductComment;
import net.shopxx.entity.Productitem;
import net.shopxx.entity.PropertiesValue;
import net.shopxx.service.ArticleCategoryService;
import net.shopxx.service.FooterService;
import net.shopxx.service.FriendLinkService;
import net.shopxx.service.GroupbuyService;
import net.shopxx.service.HtmlService;
import net.shopxx.service.IndexfloorService;
import net.shopxx.service.NavigationService;
import net.shopxx.service.ProductCategoryService;
import net.shopxx.util.SystemConfigUtil;
import net.shopxx.util.TemplateConfigUtil;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.beans.ResourceBundleModel;
import freemarker.template.Configuration;
import freemarker.template.Template;

/**
 * Service实现类 - 生成静态
 */

@Service
public class HtmlServiceImpl implements HtmlService {

	@Resource
	private FreemarkerManager freemarkerManager;
	@Resource
	private NavigationService navigationService;
	@Resource
	private FriendLinkService friendLinkService;
	@Resource
	private FooterService footerService;
	@Resource
	private ArticleCategoryService articleCategoryService;
	@Resource
	private ArticleDao articleDao;
	@Resource
	ProductCategoryService productCategoryService;
	@Resource
	private ProductDao productDao;
	@Resource
	private FlagshipStoreDao flagshipStoreDao;
	@Resource
	private BrandDao brandDao;
	@Resource
	private IndexfloorService indexfloorService;
	@Resource
	GroupbuyService groupbuyService;

	private Map<String, Object> commonDataMap;

	public void buildHtml(String templateFilePath, String htmlFilePath,
			Map<String, Object> data) {
		try {
			ServletContext servletContext = ServletActionContext
					.getServletContext();
			Configuration configuration = freemarkerManager
					.getConfiguration(servletContext);
			Template template = configuration.getTemplate(templateFilePath);
			File htmlFile = new File(servletContext.getRealPath(htmlFilePath));
			File htmlDirectory = htmlFile.getParentFile();
			if (!htmlDirectory.exists()) {
				htmlDirectory.mkdirs();
			}
			Writer out = new BufferedWriter(new OutputStreamWriter(
					new FileOutputStream(htmlFile), "UTF-8"));
			template.process(data, out);
			out.flush();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 获取公共数据
	public Map<String, Object> getCommonData() {

		if (commonDataMap == null || commonDataMap.isEmpty()) {
			Map<String, Object> commonData = new HashMap<String, Object>();
			ServletContext servletContext = ServletActionContext
					.getServletContext();
			ResourceBundle resourceBundle = ResourceBundle.getBundle("i18n");
			ResourceBundleModel resourceBundleModel = new ResourceBundleModel(
					resourceBundle, new BeansWrapper());
			SystemConfig systemConfig = SystemConfigUtil.getSystemConfig();

			String priceCurrencyFormat = SystemConfigUtil
					.getPriceCurrencyFormat();
			String priceUnitCurrencyFormat = SystemConfigUtil
					.getPriceUnitCurrencyFormat();

			String orderCurrencyFormat = SystemConfigUtil
					.getOrderCurrencyFormat();
			String orderUnitCurrencyFormat = SystemConfigUtil
					.getOrderUnitCurrencyFormat();

			commonData.put("bundle", resourceBundleModel);
			commonData.put("base", servletContext.getContextPath());
			commonData.put("systemConfig", systemConfig);
			commonData.put("priceCurrencyFormat", priceCurrencyFormat);
			commonData.put("priceUnitCurrencyFormat", priceUnitCurrencyFormat);
			commonData.put("orderCurrencyFormat", orderCurrencyFormat);
			commonData.put("orderUnitCurrencyFormat", orderUnitCurrencyFormat);
			commonData.put("topNavigationList", navigationService
					.getTopNavigationList());
			commonData.put("middleNavigationList", navigationService
					.getMiddleNavigationList());
			commonData.put("bottomNavigationList", navigationService
					.getBottomNavigationList());
			commonData.put("friendLinkList", friendLinkService.getAll());
			commonData.put("pictureFriendLinkList", friendLinkService
					.getPictureFriendLinkList());
			commonData.put("textFriendLinkList", friendLinkService
					.getTextFriendLinkList());
			commonData.put("footer", footerService.getFooter());
			// 产品分类
			List<ProductCategory> rootProductCategoryList = productCategoryService
					.getRootProductCategoryList();
			for (ProductCategory productCateTemp : rootProductCategoryList) {
				productCateTemp.setBrandList(productDao.getBrandList(
						productCateTemp, 0, 10));
			}
			// 一级分类
			commonData.put("rootProductCategoryList", rootProductCategoryList);
			commonDataMap = commonData;
		}
		return commonDataMap;
	}

	public void baseJavascriptBuildHtml() {
		Map<String, Object> data = getCommonData();
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.BASE_JAVASCRIPT);
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	@SuppressWarnings("unchecked")
	public void indexBuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.INDEX);
		Map<String, Object> data = getCommonData();

		// 首页店招图片
		List<String> bannerList = new ArrayList<String>();
		bannerList = flagshipStoreDao
				.getFlagshipStoreList(FlagshipStore.BANNER_LIST_COUNT);
		if (bannerList.isEmpty()) {
			bannerList.add("/upload/image/banner1.jpg");
			bannerList.add("/upload/image/banner2.jpg");
			bannerList.add("/upload/image/banner3.jpg");
		}

		data.put("bannerList", bannerList);
		// 特价商品
		data
				.put(
						"specPriceProductList",
						productDao
								.getSpecPriceProductList(Product.SPEC_PRICE_PRODUCT_LIST_COUNT));
		// 推荐商品
		data.put("hotProductList", productDao
				.getHotProductList(Product.MAX_HOT_PRODUCT_LIST_COUNT));
		// 推荐品牌
		data.put("brandList", brandDao
				.getBrandList(Brand.RECOMMEND_BRAND_LIST_COUNT));
		Pager pager = new Pager();
		pager.setPageSize(1);
		data.put("groupbuyList", groupbuyService.findByPager(pager).getList());
		Pager pagerTime = new Pager();
		pagerTime.setPageSize(8);
		// pagerTime.setKeyword("1");
		// pagerTime.setProperty("");
		data.put("limitTimeList", groupbuyService.findByPager(pagerTime)
				.getList());

		List<ProductCategory> rootProductCategoryList = (List<ProductCategory>) data
				.get("rootProductCategoryList");
		List<CategoryBean> categoryBeanList = new ArrayList<CategoryBean>();
		for (ProductCategory productCategory : rootProductCategoryList) {
			CategoryBean bean = new CategoryBean();
			bean.setCategory(productCategory);
			bean.setChildCategory(productCategory.getChildren());
			bean.setSpecPriceProduct(productDao.getSpecPriceProductList(
					productCategory, Product.SPEC_PRICE_PRODUCT_LIST_COUNT));
			List<CategoryBean> childrenBeanList = new ArrayList<CategoryBean>();
			for (ProductCategory child : productCategory.getChildren()) {
				CategoryBean childBean = new CategoryBean();
				childBean.setCategory(child);
				childBean.setProduct(productDao.getProductList(child, 0,
						Product.SPEC_PRICE_PRODUCT_LIST_COUNT));
				childrenBeanList.add(childBean);
			}
			bean.setChildren(childrenBeanList);
			categoryBeanList.add(bean);
		}
		data.put("categoryBeanList", categoryBeanList);

		List<Indexfloor> indexfloorList = indexfloorService.getAll();

		data.put("indexfloorList", indexfloorList);

		data.put("rootArticleCategoryList", articleCategoryService
				.getRootArticleCategoryList());
		data
				.put(
						"recommendArticleList",
						articleDao
								.getRecommendArticleList(Article.MAX_RECOMMEND_ARTICLE_LIST_COUNT));
		data.put("hotArticleList", articleDao
				.getHotArticleList(Article.MAX_HOT_ARTICLE_LIST_COUNT));
		data.put("newArticleList", articleDao
				.getNewArticleList(Article.MAX_NEW_ARTICLE_LIST_COUNT));
		List<ArticleCategory> allArticleCategory = articleCategoryService
				.getAll();
		data.put("allArticleCategoryList", allArticleCategory);
		Map<String, List<ArticleCategory>> articleCategoryMap = new HashMap<String, List<ArticleCategory>>();
		Map<String, List<Article>> recommendArticleMap = new HashMap<String, List<Article>>();
		Map<String, List<Article>> hotArticleMap = new HashMap<String, List<Article>>();
		Map<String, List<Article>> newArticleMap = new HashMap<String, List<Article>>();
		for (ArticleCategory articleCategory : allArticleCategory) {
			articleCategoryMap.put(articleCategory.getId(),
					articleCategoryService
							.getChildrenArticleCategoryList(articleCategory));
			recommendArticleMap.put(articleCategory.getId(), articleDao
					.getRecommendArticleList(articleCategory,
							Article.MAX_RECOMMEND_ARTICLE_LIST_COUNT));
			hotArticleMap.put(articleCategory.getId(), articleDao
					.getHotArticleList(articleCategory,
							Article.MAX_HOT_ARTICLE_LIST_COUNT));
			newArticleMap.put(articleCategory.getId(), articleDao
					.getNewArticleList(articleCategory,
							Article.MAX_NEW_ARTICLE_LIST_COUNT));
		}
		data.put("articleCategoryMap", articleCategoryMap);
		data.put("recommendArticleMap", recommendArticleMap);
		data.put("hotArticleMap", hotArticleMap);
		data.put("newArticleMap", newArticleMap);

		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);

		categoryBuildHtml(rootProductCategoryList);
	}

	public void categoryBuildHtml(List<ProductCategory> rootCategoryList) {
		for (ProductCategory productCategory : rootCategoryList) {
			rootCategoryBuildHtml(productCategory);
		}
	}

	public void rootCategoryBuildHtml(ProductCategory rootCategory) {
		List<CategoryBean> categoryBeanList = new ArrayList<CategoryBean>();
		for (ProductCategory productCategory : rootCategory.getChildren()) {
			CategoryBean bean = new CategoryBean();
			bean.setCategory(productCategory);
			bean.setChildCategory(productCategory.getChildren());
			bean.setProduct(productDao.getProductList(productCategory, 0,
					Product.SPEC_PRICE_PRODUCT_LIST_COUNT));
			categoryBeanList.add(bean);
			middleCategoryBuildHtml(productCategory);
		}
		
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.ROOT_CATEGORY);
		Map<String, Object> data = getCommonData();

		// 首页店招图片
		List<String> bannerList = new ArrayList<String>();
		// bannerList =
		// flagshipStoreDao.getFlagshipStoreList(FlagshipStore.BANNER_LIST_COUNT);
		if (bannerList.isEmpty()) {
			bannerList.add("/upload/image/banner1.jpg");
			bannerList.add("/upload/image/banner2.jpg");
			bannerList.add("/upload/image/banner3.jpg");
		}

		data.put("bannerList", bannerList);
		// 新品商品
		data.put("newProductList", productDao.getNewProductList(rootCategory,
				Product.SPEC_PRICE_PRODUCT_LIST_COUNT));
		// 特价商品
		data.put("specPriceProductList", productDao.getSpecPriceProductList(
				rootCategory, Product.SPEC_PRICE_PRODUCT_LIST_COUNT));
		// 热销商品
		data.put("hotProductList", productDao.getHotProductList(rootCategory,
				Product.MAX_HOT_PRODUCT_LIST_COUNT));
		// 产品分类
		data.put("rootCategory", rootCategory);
		data.put("categoryBeanList", categoryBeanList);
		String htmlFilePath = rootCategory.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);

		
	}

	public void middleCategoryBuildHtml(ProductCategory middleCategory) {

		List<CategoryBean> categoryBeanList = new ArrayList<CategoryBean>();
		if (middleCategory.getChildren() != null
				&& middleCategory.getChildren().size() > 0) {
			for (ProductCategory childCategory : middleCategory.getChildren()) {
				CategoryBean bean = new CategoryBean();
				bean.setCategory(childCategory);
				bean.setChildCategory(childCategory.getChildren());
				bean.setProduct(productDao.getProductList(childCategory, 0,
						Product.SPEC_PRICE_PRODUCT_LIST_COUNT));
				categoryBeanList.add(bean);
				middleCategoryBuildHtml(childCategory);
			}
		}

		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.MIDDLE_CATEGORY);
		Map<String, Object> data = getCommonData();

		// 首页店招图片
		List<String> bannerList = new ArrayList<String>();
		// bannerList =
		// flagshipStoreDao.getFlagshipStoreList(FlagshipStore.BANNER_LIST_COUNT);
		if (bannerList.isEmpty()) {
			bannerList.add("/upload/image/banner1.jpg");
			bannerList.add("/upload/image/banner2.jpg");
			bannerList.add("/upload/image/banner3.jpg");
		}

		data.put("bannerList", bannerList);
		// 新品商品
		data.put("newProductList", productDao.getNewProductList(middleCategory,
				Product.SPEC_PRICE_PRODUCT_LIST_COUNT));
		// 特价商品
		data.put("specPriceProductList", productDao.getSpecPriceProductList(
				middleCategory, Product.SPEC_PRICE_PRODUCT_LIST_COUNT));
		// 热销商品
		data.put("hotProductList", productDao.getHotProductList(middleCategory,
				Product.MAX_HOT_PRODUCT_LIST_COUNT));
		// 产品分类
		data.put("rootCategory", middleCategory);
		data.put("categoryBeanList", categoryBeanList);

		String htmlFilePath = middleCategory.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	public void loginBuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.LOGIN);
		Map<String, Object> data = getCommonData();
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	@Transactional
	public void articleContentBuildHtml(Article article) {
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.ARTICLE_CONTENT);
		ArticleCategory articleCategory = article.getArticleCategory();
		Map<String, Object> data = getCommonData();
		data.put("article", article);
		data.put("pathList", articleCategoryService
				.getArticleCategoryPathList(article));
		data.put("rootArticleCategoryList", articleCategoryService
				.getRootArticleCategoryList());
		data.put("recommendArticleList", articleDao.getRecommendArticleList(
				articleCategory, Article.MAX_RECOMMEND_ARTICLE_LIST_COUNT));
		data.put("hotArticleList", articleDao.getHotArticleList(
				articleCategory, Article.MAX_HOT_ARTICLE_LIST_COUNT));
		data.put("newArticleList", articleDao.getNewArticleList(
				articleCategory, Article.MAX_NEW_ARTICLE_LIST_COUNT));
		String htmlFilePath = article.getHtmlFilePath();
		String prefix = StringUtils.substringBeforeLast(htmlFilePath, ".");
		String extension = StringUtils.substringAfterLast(htmlFilePath, ".");
		List<String> pageContentList = article.getPageContentList();
		article.setPageCount(pageContentList.size());
		articleDao.update(article);
		articleDao.flush();
		for (int i = 0; i < pageContentList.size(); i++) {
			data.put("content", pageContentList.get(i));
			data.put("pageNumber", i + 1);
			data.put("pageCount", pageContentList.size());
			String templateFilePath = htmlConfig.getTemplateFilePath();
			String currentHtmlFilePath = null;
			if (i == 0) {
				currentHtmlFilePath = htmlFilePath;
			} else {
				currentHtmlFilePath = prefix + "_" + (i + 1) + "." + extension;
			}
			buildHtml(templateFilePath, currentHtmlFilePath, data);
		}
	}

	public void productContentBuildHtml(Product product) {
		// if(true)
		// return;
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.PRODUCT_CONTENT);
		ProductCategory productCategory = product.getProductCategory();
		productCategory.setBrandList(productDao.getBrandList(productCategory,
				0, 10));
		Map<String, Object> data = getCommonData();
		data.put("product", product);
		data.put("productComment", calculateComment(product
				.getProductCommentSet()));
		data.put("pathList", productCategoryService
				.getProductCategoryPathList(product));
		data.put("bestProductList", productDao.getBestProductList(
				productCategory, Product.MAX_BEST_PRODUCT_LIST_COUNT));
		data.put("hotProductList", productDao.getHotProductList(
				productCategory, Product.MAX_HOT_PRODUCT_LIST_COUNT));
		data.put("newProductList", productDao.getNewProductList(
				productCategory, Product.MAX_NEW_PRODUCT_LIST_COUNT));
		data.put("sizeList", getSizeSet(product));
		data.put("color_size", getColor_Size(product));
		data.put("size_color", getSize_Color(product));
		data.put("color_size_item", color_size_item(product));

		String htmlFilePath = product.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	private Set<PropertiesValue> getSizeSet(Product product) {
		Set<PropertiesValue> ret = new HashSet<PropertiesValue>();
//		for (ProductColor productColor : product.getProductColorList()) {
			for (Productitem item : product.getProductitemSet()) {
				if(item.getPropertiesValue()==null)
					continue;
				ret.add(item.getPropertiesValue());
			}
//		}
		return ret;
	}

	private Map<String, Set<String>> getColor_Size(Product product) {
		Map<String, Set<String>> retMap = new HashMap<String, Set<String>>();
//		for (ProductColor productColor : product.getProductColorList()) {
//			Set<String> tempSet = retMap.get(productColor.getColor().getId());
//			if (tempSet == null) {
//				tempSet = new HashSet<String>();
//				retMap.put(productColor.getColor().getId(), tempSet);
//			}
//			for (Productitem item : productColor.getProductitemSet()) {
//				tempSet.add(item.getPropertiesValue().getId());
//			}
//		}
		for (Productitem item : product.getProductitemSet()) {
			if(item.getColor()==null)
				continue;
			Set<String> tempSet = retMap.get(item.getColor().getId());
			if (tempSet == null) {
				tempSet = new HashSet<String>();
				retMap.put(item.getColor().getId(), tempSet);
			}
			tempSet.add(item.getPropertiesValue().getId());
		}
		
		
		return retMap;
	}

	private Map<String, Set<String>> getSize_Color(Product product) {
		Map<String, Set<String>> retMap = new HashMap<String, Set<String>>();
//		for (ProductColor productColor : product.getProductColorList()) {
//			for (Productitem item : productColor.getProductitemSet()) {
//				Set<String> tempSet = retMap.get(item.getPropertiesValue()
//						.getId());
//				if (tempSet == null) {
//					tempSet = new HashSet<String>();
//					retMap.put(item.getPropertiesValue().getId(), tempSet);
//				}
//				tempSet.add(productColor.getColor().getId());
//			}
//		}
		
		for (Productitem item : product.getProductitemSet()) {
			if(item.getPropertiesValue()==null)
				continue;
			Set<String> tempSet = retMap.get(item.getPropertiesValue()
					.getId());
			if (tempSet == null) {
				tempSet = new HashSet<String>();
				retMap.put(item.getPropertiesValue().getId(), tempSet);
			}
			tempSet.add(item.getColor().getId());
		}
		
		return retMap;
	}

	private Map<String, String> color_size_item(Product product) {
		Map<String, String> retMap = new HashMap<String, String>();
		for(Productitem item: product.getProductitemSet())
		{
			if(item.getColor()==null && item.getPropertiesValue()==null)
				continue;
			String value = item.getId();
			String key = (item.getColor()==null?"":item.getColor().getId()) + "_"
					+ (item.getPropertiesValue()==null?"":item.getPropertiesValue().getId());
			retMap.put(key, value);
		}
		System.out.println("cu:"+retMap.size());
		return retMap;
	}

	public CommentUtil calculateComment(Set<ProductComment> productCommentSet) {
		int goodNum = 0, midNum = 0, badNum = 0, total = 0;
		for (ProductComment productComment : productCommentSet) {
			total++;
			switch (productComment.getRank()) {
			case 0:
			case 1:
			case 2:
				badNum++;
				break;
			case 3:
			case 4:
				midNum++;
				break;
			case 5:
				goodNum++;
				break;
			default:
				midNum++;
				break;
			}
		}
		return new CommentUtil(badNum, midNum, goodNum, total);
	}

	public void groupbuyContentBuildHtml(Groupbuy groupbuy) {
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.GROUPBUY_CONTENT);
		ProductCategory productCategory = groupbuy.getProduct()
				.getProductCategory();
		Map<String, Object> data = getCommonData();
		data.put("groupbuy", groupbuy);
		data.put("pathList", productCategoryService
				.getProductCategoryPathList(groupbuy.getProduct()));
		data.put("rootProductCategoryList", productCategoryService
				.getRootProductCategoryList());
		data.put("bestProductList", productDao.getBestProductList(
				productCategory, Product.MAX_BEST_PRODUCT_LIST_COUNT));
		data.put("hotProductList", productDao.getHotProductList(
				productCategory, Product.MAX_HOT_PRODUCT_LIST_COUNT));
		data.put("newProductList", productDao.getNewProductList(
				productCategory, Product.MAX_NEW_PRODUCT_LIST_COUNT));
		String htmlFilePath = groupbuy.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	public void errorPageBuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.ERROR_PAGE);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "系统出现异常，请与管理员联系！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	public void errorPageAccessDeniedBuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.ERROR_PAGE);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "您无此访问权限！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	public void errorPage500BuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.ERROR_PAGE_500);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "系统出现异常，请与管理员联系！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	public void errorPage404BuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.ERROR_PAGE_404);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "您访问的页面不存在！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

	public void errorPage403BuildHtml() {
		HtmlConfig htmlConfig = TemplateConfigUtil
				.getHtmlConfig(HtmlConfig.ERROR_PAGE_403);
		Map<String, Object> data = getCommonData();
		data.put("errorContent", "系统出现异常，请与管理员联系！");
		String htmlFilePath = htmlConfig.getHtmlFilePath();
		String templateFilePath = htmlConfig.getTemplateFilePath();
		buildHtml(templateFilePath, htmlFilePath, data);
	}

}